﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Speech.Recognition;

namespace CodeTalk.CTSpeechCommands
{
    class UndoRedo : SpeechCommand
    {
        internal override GrammarBuilder GrammarBld(Context context, Context[] libraries)
        {
            Choices c = new Choices("undo command", "redo command");
            return new GrammarBuilder(c);
        }

        public override string Name
        {
            get { return "UndoRedo"; }
        }

        public override string Description
        {
            get { return "Undo/Redo"; }
        }

        internal override bool IsUndoable
        {
            get { return false; }
        }

        public override string GetAlternativesFeedback(string recognizedText, SemanticValue semValue)
        {
            return recognizedText;
        }

        internal override bool CanSpokenFormMatch(string spokenForm)
        {
            return spokenForm == "undo command" || spokenForm == "redo command";
        }

        internal override object Execute(SpeechMode callingMode, string recognizedText, SemanticValue semValue)
        {
            if (recognizedText.StartsWith("u"))
            {
                string undoCommand = ActionManager.UndoCommand();
                if (undoCommand != null)
                    callingMode.CurrentGuiHandler.SetPrimaryFeedback("Undo: " + undoCommand);
                else
                    callingMode.CurrentGuiHandler.SetErrorFeedback("No command to undo!");
            }
            else if (recognizedText.StartsWith("r"))
            {
                string redoCommand = ActionManager.RedoCommand();
                if (redoCommand != null)
                    callingMode.CurrentGuiHandler.SetPrimaryFeedback("Redo: " + redoCommand);
                else
                    callingMode.CurrentGuiHandler.SetErrorFeedback("No command to redo!");
            }

            return null;
        }

        internal override void Undo(SpeechMode callingMode, string recognizedText, SemanticValue semValue, object undoObject)
        {
            throw new NotSupportedException();
        }
    }
}
